﻿using System;
using System.Collections.Generic;

namespace FunctionalCLR.Core {
    public abstract class FuncNode : Node {
        public int ParameterCount {
            get;
            set;
        }

        public List<Node> Children {
            get;
            set;
        }

        public FuncNode() {
            this.Precedence = Int32.MaxValue;
            this.Children = new List<Node>();
        }

        public int Precedence {
            get;
            set;
        }

        public virtual FuncNode GetReversedFunction(int index) {
            throw new NoOppositeOperatorException(string.Format(
                "Function {0} cannot be transformed", this.Value));
        }

        public double[] EvaluateChildren() {
            double[] results = new double[Children.Count];
            for (int index = 0; index < Children.Count; index++) {
                results[index] = Convert.ToDouble(
                    Children[index].Evaluate());
            }

            return results;
        }

        public override object Accept(IVisitor visitor) {
            return visitor.Visit(this);
        }
    }
}
